/*
 *  hihocoder.com
 *
 *  Category: Data Structure
 */

/*-------- Includes --------*/
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int top         = 0;
int stk[200002] = {0};
int add[200002] = {0};

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int  N;
    char cstr[8];
    int  x, k;

    cin >> N;

    for (int i = 0; i < N; ++i) {
        cin >> cstr;

        if (cstr[1] == 'u') {
            cin >> x;
            stk[top++] = x;
        } else if (cstr[1] == 'o') {
            x  = stk[--top];
            x += add[top];
            cout << x << endl;

            if (top > 0)
                add[top-1] += add[top];
            add[top]    = 0;
        } else {
            cin >> k >> x;

            add[k-1] += x;
        }
    }

    return 0;
}

/*-------- Functions --------*/

